package com.ruoyi.gcgl.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.common.utils.wx.WxSend;
import com.ruoyi.gcgl.mapper.GcSendTipMapper;
import com.ruoyi.gcgl.service.IGcSendTipService;

@Service
public class GcSendTipServiceImpl implements IGcSendTipService {
	
	@Autowired
    private GcSendTipMapper gcSendTipMapper;
	
	private String zjl_openId = "oeW8c6zR7lIkqThkhmSd5EipUvOQ";//总经理
	private String cw_openId = "oeW8c62_xnanHgZ85ngARZ6JG0Yw";//财务
	private String gcb_openId = "oeW8c67PqN-VtD2jA4nV0m7kX2O0";//工程部
	
//	private String zjl_openId = "oeW8c69mPmGoyTKs2J5XcMNSso1I";//总经理
//	private String cw_openId = "oeW8c69mPmGoyTKs2J5XcMNSso1I";//财务
//	private String gcb_openId = "oeW8c69mPmGoyTKs2J5XcMNSso1I";
	private String sysUrl = "http://lkgnews.cn:90";
	
	public final String fyhx = "fyhx";//费用核销
	public final String clbx = "clbx";//差旅报销
	public final String qtfk = "qtfk";//其它付款
	public final String qttk = "qttk";//其它退款
	public final String jhk = "jhk";//借还款
	
	public final String yzsp = "yzsp";//印章审批
	public final String gzt = "gzt";//工资条
	
	public final String cbyg = "cbyg";//成本预估
	public final String xmht = "xmht";//项目立项
	public final String bzj = "bzj";//项目保证金/服务费
	public final String sbclht = "sbclht";//设备材料合同
	public final String sgazht = "sgazht";//施工安装合同
	public final String other = "other";//工程其它合同
	public final String fk = "fk";//工程项目支付
	public final String sqkp = "sqkp";//申请开票
	
	@Override
	public Map sendTipXm(String type, String name, String code,
			String createUser, String riq, String status, String toUser,
			String url) {
		Map rep = new HashMap();
		rep.put("flag", false);
		String toCreateUser = "";
		List<Map> userlis = gcSendTipMapper.selectGcToUserById(createUser);
		if(userlis!=null && userlis.size()>0){
			toCreateUser = userlis.get(0).get("openId").toString();//创建人
			try {
				if(type.equals(cbyg)){
					//成本评估
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(xmht)){
					//项目合同
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(bzj)){
					//项目中标服务费
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(sbclht)){
					//设备材料合同
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(sgazht)){
					//施工合同
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(other)){
					//项目其它合同
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待工程部审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(fk)){
					//付款
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(sqkp)){
					//付款
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}
				
				rep.put("flag", true);
			} catch (Exception e) {
				// TODO: handle exception
				e.getLocalizedMessage();
			}
			
		}
		return null;
	}
	
	@Override
	public Map sendTip(String type, String name, String code,
			String createUser, String riq, String status, String toUser,
			String url) {
		Map rep = new HashMap();
		rep.put("flag", false);
		String toCreateUser = "";
		List<Map> userlis = gcSendTipMapper.selectGcToUserById(createUser);
		if(userlis!=null && userlis.size()>0){
			toCreateUser = userlis.get(0).get("openId").toString();//创建人
			
			try {
				if(type.equals(fyhx)){
					//费用核销-财务-总经理
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(clbx)){
					//差旅报销-财务-总经理
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(qtfk)){
					//其它付款-总经理-财务
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(qttk)){
					//其它退款-财务-总经理
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(jhk)){
					//借还款-财务-总经理
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("5")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("6")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("7")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("8")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("9")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(yzsp)){
					//印章审批-印章管理员
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待印章管理员审核", 
								gcb_openId, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}else if(type.equals(gzt)){
					//工资-财务-总经理
					if(status.equals("0")){
						sendWx(name, code, createUser, riq, "待财务审核", 
								cw_openId, sysUrl);
					}else if(status.equals("1")){
						sendWx(name, code, createUser, riq, "待总经理审核", 
								zjl_openId, sysUrl);
					}else if(status.equals("2")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}else if(status.equals("3")){
						sendWx(name, code, createUser, riq, "审核通过", 
								toCreateUser, sysUrl);
					}else if(status.equals("4")){
						sendWx(name, code, createUser, riq, "审核拒绝", 
								toCreateUser, sysUrl);
					}
				}
				
				rep.put("flag", true);
			} catch (Exception e) {
				// TODO: handle exception
				e.getLocalizedMessage();
				
			}
			
		}
		
		return rep;
	}
	
	/**
	 * 
	 * @param name
	 * @param code
	 * @param createUser
	 * @param riq
	 * @param status
	 * @param toUser
	 * @param url
	 * @return
	 */
	private boolean sendWx(String name, String code,
			String createUser, String riq, String status, String toUser,
			String url){
		try {
			
			//微信 
			WxSend send = new WxSend();
			send.sendWx(name, code, createUser, riq, status, toUser, url);
		} catch (Exception e) {
			// TODO: handle exception
			e.getLocalizedMessage();
			return false;
		}
		return true;
	}
}